package com.jjty.dataGenerator.sxhcampus;

import com.alibaba.fastjson.JSONObject;
import com.jjty.dataGenerator.exception.ServiceException;
import com.jjty.dataGenerator.sxhcampus.vo.BaseResultSx;
import com.jjty.dataGenerator.sxhcampus.vo.EsActiveData;
import com.jjty.dataGenerator.utils.HttpsRequest1;
import org.springframework.stereotype.Service;

/**
 * @Author: huangyulong
 * @createTime: 2023-11-08 17:02
 * @Description:
 */
@Service
public class ApiCallSxHcampus {

//    public BaseResultSx sendActiveData(EsActiveData activeData){
//        String s = JSONObject.toJSONString(activeData);
//        System.out.println("参数："+s);
//        HttpResponse<String> httpResponse = Unirest.post(SxHCampusConfig.sendActiveDataUrl)
//                .header("Content-Type", "application/json")
//                .header("Accept", "*/*")
//                .header("Connection", "keep-alive")
//                .body(s)
//                .asString();
//        String s1 = httpResponse.getBody();
//        System.out.println(s1);
//        BaseResultSx baseResultSx = JSONObject.parseObject(s1, BaseResultSx.class);
//        if(baseResultSx.getRet()!=0){
//            throw new ServiceException(baseResultSx.getMsg());
//        }
//        return baseResultSx;
//    }

    public BaseResultSx sendActiveData(EsActiveData activeData){
        String s = JSONObject.toJSONString(activeData);
        System.out.println("参数："+s);
//        HttpResponse<String> httpResponse = Unirest.post(SxHCampusConfig.sendActiveDataUrl)
//                .header("Content-Type", "application/json")
//                .header("Accept", "*/*")
//                .header("Connection", "keep-alive")
//                .body(s)
//                .asString();
//        String s1 = httpResponse.getBody();
        String s1 = HttpsRequest1.sendPost(SxHCampusConfig.sendActiveDataUrl, s);
        System.out.println(s1);
        BaseResultSx baseResultSx = JSONObject.parseObject(s1, BaseResultSx.class);
        if(baseResultSx.getRet()!=0){
            throw new ServiceException(baseResultSx.getMsg());
        }
        return baseResultSx;
    }

}
